<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/list.css">

</head>
<body>
<div class="nav">
    <img src="https://tse3-mm.cn.bing.net/th/id/OIP-C.wb9I_pEZGVG3RIQtuLCXNQHaHZ?w=181&h=180&c=7&r=0&o=7&dpr=1.3&pid=1.7&rm=3" alt="">
    <span class="blog-title">我的博客系统</span>
    <div class="space"></div>
    <a class="nav-span" href="blog_list.html">主页</a>
    <a class="nav-span" href="blog_edit.html">写博客</a>
    <a class="nav-span" href="#" onclick="logout()">注销</a>
</div>

<div class="container">
    <div class="left">
        <div class="card">
            <img src="pic/doge.jpg" alt="">
            <h3 class="name">比特汤老师</h3>
            <a class="git" href="#">GitHub 地址</a>
            <div class="row">
                <span>文章</span>
                <span>分类</span>
            </div>
            <div class="row">
                <span>2</span>
                <span>1</span>
            </div>
        </div>
    </div>
    <div class="right">

    </div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/common.js"></script>
<script>

//获取博客列表
    $.ajax({
        type: "GET",
        url: "blog/selectBlogList",
        success: function (result) {
            console.log(result);
            var html = "";
            if (result.code == "Success") {
                var blogs = result.data;
                for (var blog of blogs) {
                    html += '<div class="blog">';
                    html += '<div class="title">' + blog.title + '</div>';
                    html += '<div class="date">' + blog.updateTime + '</div>';
                    html += '<div class="desc">' + blog.content + '</div>';
                    html += '<a class="detail" href="blog_detail.html?id=' + blog.id + '">查看全文</a>';
                    html += '</div>';
                }
                $(".right").html(html);
            }
        },
        error: function (error) {
            if (error != null && error.status == 401) {
                //3秒后跳转到login
                // setTimeout(function () {
                //     location.assign("blog_login.html");
                //     return;
                // },3000)
                console.log(localStorage.getItem("token"));
                //location.href = "blog_login.html";
            }
        }
    });
    $.ajax( {
        type: "GET",
        url: "user/selectUserInfo",
        success: function (result) {
            if (result.code == "Success") {
                var user = result.data;
                console.log(user);
                $(".name").html(user.userName);
                $(".git").attr("href", user.githubUrl);
                $.ajax({
                    type: "GET",
                    url: "blog/selectBlogCount",
                    success: function (result) {
                        console.log(result);
                        if (result.code == "Success") {
                            $(".row:eq(1) span:eq(0)").html(result.data);
                        }
                    }
                })
            }else {
                alert(result.errMessage);
            }

        },
        error: function (error) {
            if (error != null && error.status == 401) {
                alert("未登录");
                location.href = "blog_login.html";
            }
        }
    })


    // function logout() {
    //     $.ajax({
    //         type: "POST",
    //         url: "user/logout",
    //         success: function (result) {
    //             if (result.code == "Success") {
    //                 location.assign("blog_login.html");
    //             } else {
    //                 alert(result.message);
    //             }
    //         }
    //     })
    // }
    </script>
</body>
</html>